﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input id="id" type="hidden" name="id" />
        <div class="form-group">
            <label class="col-sm-3 control-label ">角色名称<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="roleName" name="RoleName" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">显示顺序</label>
            <div class="col-sm-8">
                <input id="roleSort" name="roleSort" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">状态</label>
            <div class="col-sm-8" id="roleStatus" name="RoleStatus">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">备注</label>
            <div class="col-sm-8">
                <input id="remark" name="Remark" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">菜单权限</label>
            <div class="col-sm-8">
                <div id="menuTree" class="ztree ztree-border"></div>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        $("#roleStatus").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(StatusEnum).EnumToDictionaryString())) });

        loadMenuTree();

        $("#form").validate({
            rules: {
                roleName: { required: true }
            }
        });
       /* getForm()*/
        setTimeout(function () { getForm(); },500)
    });

    function loadMenuTree() {
         $('#menuTree').ysTree({
             async: false,
             treeNodeKey: "id",         //设置节点唯一标识属性名称
             treeNodeParentKey: "pid",  //设置节点的父节点唯一标识属性名称
            url: '@Url.Content("~/SystemManage/Menu/GetMenuTreeListJson")',
            check: { enable: true },
            expandLevel: 0
        })
    }

    function getForm() {
        //修改赋值使用
        var editData = storage.get("editData");
        if (editData != null && editData.length > 0) {
            var data = JSON.parse(editData);
            //表单赋值
            $("#form").setWebControls(data);
            $('#menuTree').ysTree("setCheckedNodes", data.menuIds);
        } else {
            //界面初始化 给状态、性别赋值
            var defaultData = {};
            defaultData.roleStatus = 1;
            $("#form").setWebControls(defaultData);
        }
    }

    //提交数据
    function submitForm(index) {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls();
            postData.MenuIds = $('#menuTree').ysTree("getCheckedNodes");
            $.operate.save("/SystemManage/Role/SaveFormJson", postData);
        }
    }
</script>
